//
//  AccountMenuView.m
//  跨界收
//
//  Created by Allen on 2018/10/27.
//  Copyright © 2018年 gztx. All rights reserved.
//

#import "AccountMenuView.h"
#import "AccountItemData.h"
#import "WYFItemView.h"

@implementation AccountMenuView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self createMenuItems];
    }
    return self;
}
- (void)createMenuItems
{
    AccountItemData *item = [[AccountItemData alloc] init];
    CGFloat width = 80.0;
    CGFloat x = (SCREEN_WIDTH - 4*80)/5.0;
    CGFloat y = (200-160)/3.0;
    for (NSInteger i = 0; i < item.itemsArray.count; i ++) {
        CGFloat X = i%4*(x+width)+x;
        CGFloat Y = i/4*(y+width)+10;
        WYFItemView *itemView = [[WYFItemView alloc] initWithFrame:CGRectMake(X, Y, width, width)];
        itemView.tag = 1000+i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
        [itemView addGestureRecognizer:tap];
        [itemView.iconButton setImage:[UIImage imageNamed:item.itemsArray[i]] forState:UIControlStateNormal];
        if (SCREEN_WIDTH<375.0) {
            itemView.titleLabel.font = [UIFont systemFontOfSize:14.0];
        }
        itemView.titleLabel.text = item.titleArray[i];
        [self addSubview:itemView];
    }
}
- (void)tapView:(UITapGestureRecognizer *)tap
{
    if (self.tapItemViewBlock) {
        if ([tap.view isKindOfClass:[WYFItemView class]]) {
            WYFItemView *view = (WYFItemView *)tap.view;
            self.tapItemViewBlock(view.tag);
        }
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
